﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class ThamSoDAO
    {
        #region 2. Sua
        public static bool SuaBangThamSo(ThamSoDTO thamso){
            bool result = false;
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@TuoiToiDa", thamso.TuoiToiDa));
                sqlParams.Add(new SqlParameter("@TuoiToiThieu", thamso.TuoiToiThieu));
                sqlParams.Add(new SqlParameter("@ThoiHanThe", thamso.ThoiHanThe));
                sqlParams.Add(new SqlParameter("@KhoangCachNamXB", thamso.KhoangCachNamXB));
                sqlParams.Add(new SqlParameter("@SoLuongMuonToiDa", thamso.SoLuongMuonToiDa));
                sqlParams.Add(new SqlParameter("@ThoiGianMuonToiDa", thamso.ThoiGianMuonToiDa));
                sqlParams.Add(new SqlParameter("@TienPhat", thamso.TienPhat));

                int n = SqlDataAccessHelper.ExecuteNoneQuery("usp_UpdateTHAMSO", sqlParams);

                if (n == 1)
                {
                    result = true;
                }

            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
        #region 4. Tim kiem
        public static ThamSoDTO TimThamSo(){
            ThamSoDTO result = new ThamSoDTO();
            try
            {
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("usp_SelectTHAMSO");
                DataRow dr = dt.Rows[0];

                result.TuoiToiDa = byte.Parse(dr["TuoiToiDa"].ToString());
                result.TuoiToiThieu = byte.Parse(dr["TuoiToiThieu"].ToString());
                result.ThoiHanThe = int.Parse(dr["ThoiHanThe"].ToString());
                result.KhoangCachNamXB = int.Parse(dr["KhoangCachNamXB"].ToString());
                result.SoLuongMuonToiDa = int.Parse(dr["SoLuongMuonToiDa"].ToString());
                result.ThoiGianMuonToiDa = int.Parse(dr["ThoiGianMuonToiDa"].ToString());
                result.TienPhat = decimal.Parse(dr["TienPhat"].ToString());
            }
            catch (System.Exception ex)
            {
               
            }
            return result;
        }
        #endregion
    }
}
